package cn.tlb.okhttp;

import android.test.AndroidTestCase;
import android.util.Log;

import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;

/**
 * Created by 汤林冰 on 2015/12/3 15:26.
 */
public class Test01 extends AndroidTestCase {
    private static final String TAG = "Test01";


    ///////////////////////////////////////////////////////////////////////////
    // okhttp
    ///////////////////////////////////////////////////////////////////////////

    public void test01(){
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url("http://www.baidu.com").build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                Log.i(TAG, request.body().toString());
                Log.i(TAG, e.getMessage());
                e.printStackTrace();
            }

            @Override
            public void onResponse(Response response) throws IOException {
                Log.i(TAG, response.body().string());
            }
        });

    }
}
